﻿<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="/ViewV5/CSS/icfont_qj/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="/ViewV5/CSS/animate.css">
    <link rel="stylesheet" type="text/css" href="/ViewV5/CSS/bootstrap3.3.5/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="/ViewV5/CSS/default.css">
    <link rel="stylesheet" type="text/css" href="/ViewV5/CSS/index.css">
    <link href="/ViewV5/JS/umeditor122/themes/default/css/umeditor.css" rel="stylesheet" />
    <link href="/ViewV5/JS/fullcalendar/fullcalendar.css" rel="stylesheet" />
    <link href="/ViewV5/JS/fullcalendar/fullcalendar.print.css" rel="stylesheet" />
    <link href="/ViewV5/JS/range/range.css" rel="stylesheet" />
    <link rel="stylesheet" href="/ViewV5/JS/YanGrid/jqwidgets/styles/jqx.base.css" />
    <link rel="stylesheet" href="/ViewV5/JS/YanGrid/jqwidgets/styles/jqx.office.css" />
    <script type="text/javascript" src="/ViewV5/JS/jquery-1.11.2.min.js"></script>
    <script src="/ViewV5/JS/jquery-migrate-1.1.0.min.js"></script>
    <script src="/VIEWV5/JS/YanGrid/jqwidgets/jqgridall.js"></script>
    <script type="text/javascript">
         $(document).ready(function () {

             // prepare the data
             var data = preparegriddata(200);

             var source =
            {
                localdata: data,
                datatype: "array",
                datafields:
                [
                    { name: 'firstname', type: 'string' },
                    { name: 'lastname', type: 'string' },
                    { name: 'productname', type: 'string' },
                    { name: 'available', type: 'string' },
                    { name: 'quantity', type: 'number' }
                ]
            };

             var dataAdapter = new $.jqx.dataAdapter(source);
             var columnCheckBox = null;
             var updatingCheckState = false;
             // initialize jqxGrid. Disable the built-in selection.
             $("#jqxgrid").jqxGrid(
            {
                source: dataAdapter,
                width: '100%',
                height: "520",
                theme: "office",
                groupable: true,
                rowsheight: 45,
                columnsresize: true,
                showaggregates: true,
                enablehover: false,
                editable: true,
                pageable: false,
                selectionmode: 'none',
                filterable: true,
                autoshowfiltericon: true,
                altrows: true,
                sortable: true,
                showstatusbar: true,
                columns: [
                  { text: '', datafield: 'available', columntype: 'checkbox', width: 40,
                      renderer: function () {
                          return '<div style="margin-left: 10px; margin-top: 5px;"></div>';
                      },
                      rendered: function (element) {
                          $(element).jqxCheckBox({ theme: "office", width: 16, height: 16, animationShowDelay: 0, animationHideDelay: 0 });
                          columnCheckBox = $(element);
                          $(element).on('change', function (event) {
                              var checked = event.args.checked;
                              if (checked == null || updatingCheckState) return;
                              var rowscount = $("#jqxgrid").jqxGrid('getdatainformation').rowscount;
                              $("#jqxgrid").jqxGrid('beginupdate');

                              if (checked) {
                                  $("#jqxgrid").jqxGrid('selectallrows');
                              }
                              else if (checked == false) {
                                  $("#jqxgrid").jqxGrid('clearselection');
                              }

                              for (var i = 0; i < rowscount; i++) {
                                  $("#jqxgrid").jqxGrid('setcellvalue', i, 'available', event.args.checked);
                              }

                              $("#jqxgrid").jqxGrid('endupdate');
                          });
                          return true;
                      }
                  },
                  { text: 'First Name', editable: false, datafield: 'firstname', width: 90 },
                  { text: 'Last Name', editable: false, datafield: 'lastname', width: 90 },
                  { text: 'Product', editable: false, datafield: 'productname', width: 200 },
                  { text: 'Quantity', editable: false, datafield: 'quantity' }
               ]
            });

             // select or unselect rows when the checkbox is checked or unchecked.
             $("#jqxgrid").on('cellendedit', function (event) {
                 alert(1)
                 if (event.args.value) {
                     $("#jqxgrid").jqxGrid('selectrow', event.args.rowindex);
                 }
                 else {
                     $("#jqxgrid").jqxGrid('unselectrow', event.args.rowindex);
                 }
                 if (columnCheckBox) {
                     var selectedRowsCount = $("#jqxgrid").jqxGrid('getselectedrowindexes').length;
                     var rowscount = $("#jqxgrid").jqxGrid('getdatainformation').rowscount;
                     updatingCheckState = true;
                     if (selectedRowsCount == rowscount) {
                         $(columnCheckBox).jqxCheckBox('check')
                     }
                     else if (selectedRowsCount > 0) {
                         $(columnCheckBox).jqxCheckBox('indeterminate');
                     }
                     else {
                         $(columnCheckBox).jqxCheckBox('uncheck');
                     }
                     updatingCheckState = false;
                 }
             });
         });
        function preparegriddata(rowscount) {
            // prepare the data
            var data = new Array();
            var firstNames =
            [
                "Andrew", "Nancy", "Shelley", "Regina", "Yoshi", "Antoni", "Mayumi", "Ian", "Peter", "Lars", "Petra", "Martin", "Sven", "Elio", "Beate", "Cheryl", "Michael", "Guylene"
            ];

             var lastNames =
            [
                "Fuller", "Davolio", "Burke", "Murphy", "Nagase", "Saavedra", "Ohno", "Devling", "Wilson", "Peterson", "Winkler", "Bein", "Petersen", "Rossi", "Vileid", "Saylor", "Bjorn", "Nodier"
            ];

            var productNames =
            [
                "Black Tea", "Green Tea", "Caffe Espresso", "Doubleshot Espresso", "Caffe Latte", "White Chocolate Mocha", "Caramel Latte", "Caffe Americano", "Cappuccino", "Espresso Truffle", "Espresso con Panna", "Peppermint Mocha Twist"
            ];

            for (var i = 0; i < rowscount; i++) {
                var row = {};
                var productindex = Math.floor(Math.random() * productNames.length);
                var quantity = 1 + Math.round(Math.random() * 10);

                row["available"] = "false";
                row["firstname"] = firstNames[Math.floor(Math.random() * firstNames.length)];
                row["lastname"] = lastNames[Math.floor(Math.random() * lastNames.length)];
                row["productname"] = productNames[productindex];
                row["quantity"] = quantity;
                data[i] = row;
            }

            return data;
        }
    </script>
</head>


<body class='default'>
    <div id='jqxWidget'>
        <div id="jqxgrid"></div>
    </div>
</body>
</html>
